(library (pipeline)
  (export ->)

  (import
   (except (rnrs base)
           let-values
           map
           error
           vector-map)
   (only (guile)
         lambda* λ))

  (define-syntax ->
    (syntax-rules ()
      ;; first expression is left unchanged
      [(-> expr) expr]
      ;; take from the back, wrap other calls
      [(-> expr* ... (op args* ...))
       (op args* ... (-> expr* ...))]
      ;; make parens unnecessary in trivial case of no further arguments
      [(-> expr* ... op)
       (op (-> expr* ...))])))
